//
//  DrawUtil.swift
//  YOKO
//
//  Created by Zoe_G on 16/5/8.
//  Copyright © 2016年 15Tec. All rights reserved.
//

import UIKit

enum CircleIconType {
    case FillWithColor //实心圆
    case StrokeWithLine //空心圆
    case HalfFillWithColor //半实心圆
    case IconNone
}

enum BarType {
    case BarStart
    case BarMiddle
    case BarEnd
    case BarNone
}

enum CellLineType {
    case LineFirst
    case LineMiddle
    case LineLast
    case LineNone
}

class DrawUtil: NSObject {
    
    static let π = CGFloat(M_PI)
    
    static func drawLine(start:CGPoint, end: CGPoint, withColor: UIColor, withWidth: CGFloat ){
        let line = UIBezierPath()
        line.moveToPoint(start)
        line.addLineToPoint(end)
        line.closePath()
        withColor.set()
        line.lineWidth = withWidth
        line.stroke()
        line.fill()
    }
    
    static func drawCircle(center: CGPoint, radius: CGFloat, circleType: CircleIconType, circleColor: UIColor, linewidth: CGFloat){
       
        
        
        switch circleType {
        case .StrokeWithLine:
            let circle = UIBezierPath(arcCenter: center, radius: radius, startAngle: 0, endAngle: 2*π, clockwise: true)
            circle.lineWidth = linewidth
            circleColor.setStroke()
            circle.stroke()
            let innerCircle = UIBezierPath(arcCenter: center, radius: radius, startAngle: 0, endAngle: 2*π, clockwise: true)
            UIColor.whiteColor().setFill()
            innerCircle.fill()
            break
            
        case .FillWithColor:
            let circle = UIBezierPath(arcCenter: center, radius: radius, startAngle: 0, endAngle: 2*π, clockwise: true)
            circle.lineWidth = linewidth
            circleColor.setStroke()
            circle.stroke()
            circleColor.setFill()
            circle.fill()
            break
            
        case .HalfFillWithColor:
            let circle = UIBezierPath(arcCenter: center, radius: radius, startAngle: 0, endAngle: 2*π, clockwise: true)
            circle.lineWidth = linewidth
            circleColor.setStroke()
            circle.stroke()
            var semiCircle = UIBezierPath(arcCenter: center, radius: radius, startAngle: π/4, endAngle: 5*π/4, clockwise: true)
            circleColor.setFill()
            semiCircle.fill()
            
            semiCircle = UIBezierPath(arcCenter: center, radius: radius, startAngle: π/4, endAngle: 5*π/4, clockwise: false)
            UIColor.whiteColor().setFill()
            semiCircle.fill()
            break
        default :
            break
        }
    }
}
